const api = require("../../utils/api.js");

Page({
  data: {
    windowWidth: wx.getSystemInfoSync().windowWidth,
    isBottom: false,
    themeList: [],
    contBarHeight: 0,
    goodsList: [],
    pageSize: 20,
    page: 1,
    sortType: 0,
    listId: 0,
    totalCount: 0
  },
  headLoad(e) {
    this.setData({
      contBarHeight: e.detail.contBarHeight
    })
  },
  onLoad: function () {
    var that = this;

    // 商品类目
    //     当前：综合
    //     其它分类。。。


    // 主题列表
    api.request({
      url: "/pdd/themeList?pageSize=8"
    }).then(data => {
      that.setData({
        themeList: data.theme_list_get_response.theme_list
      })
    })
    // 商品列表
    //    默认：综合排序，增加多种排序方式
    this.goodsPage();

  },
  // 商品列表分页
  goodsPage() {
    var that = this;
    api.request({
      url: "/pdd/goodsPage?pageSize=",
      data: {
        pageSize: that.data.pageSize,
        page: that.data.page,
        sortType: that.data.sortType,
        listId: that.data.listId
      }
    }).then(data => {
      // 解除下拉
      wx.stopPullDownRefresh();
      // console.log(data)
      that.setData({
        goodsList: that.data.goodsList.concat(data.goods_search_response.goods_list),
        page: that.data.page + 1,
        listId: data.goods_search_response.list_id,
        totalCount: data.goods_search_response.total_count
      })
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.goodsPage()
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      goodsList: []
    })
    this.goodsPage();
  }
});